{% load suit_forms %}
<fieldset class="suit-form module aligned {{ fieldset.classes }}">
    {% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %}
    {% if fieldset.description %}
        <div class="description">{{ fieldset.description|safe }}</div>
    {% endif %}
    {% for line in fieldset %}
        {% with is_single=line.fields|length_is:'1' %}

            <div class="form-group row form-row {% if is_single and line.errors or field.errors %} has-danger errors{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if field.field.is_hidden %} hidden{% endif %}{% endfor %}">

                {% for field in line %}
                    {% if is_single or forloop.first %}
                        <label for="{{ field.field.id_for_label }}" class="form-control-label {{ field.field|suit_form_label_class:fieldset }}">{{ field.label_tag }}</label>
                        <div class="{% if is_single %} {{ field.field|suit_form_field_class:fieldset }} {% else %}col-xs-12 col-sm-9 col-md-10 col-multi-fields{% endif %}">
                    {% endif %}

                {# Open multi-field #}
                {% if not is_single %}
                    <div class="multi-field {{ field.field|suit_form_field_widget_class }} {% if field.errors %} has-danger errors{% endif %}">
                    {% if not forloop.first %}
                        <label for="{{ field.field.id_for_label }}" class="form-control-label">{{ field.label_tag }}</label>
                        <div class="multi-field-content {{ field.field|suit_form_field_widget_class }}">
                    {% endif %}
                {% endif %}

                {% if field.is_readonly %}
                    <p class="form-control-static">{{ field.contents }}</p>
                {% else %}
                    {{ field.field }}
                {% endif %}
                {% if field.errors and not is_single and not field.is_readonly %}
                    <div class="text-help">
                        {{ field.errors }}
                    </div>
                {% endif %}
                {% if is_single and line.errors %}
                    <div class="text-help">
                        {{ line.errors }}
                    </div>
                {% endif %}
                {% if field.field.help_text %}
                    <small class="text-help">{{ field.field.help_text|safe }}</small>
                {% endif %}

                {# Close multi-field #}
                {% if not is_single %}

                    {# Close multi-field-content #}
                    {% if not forloop.first %}
                        </div>
                    {% endif %}

                    </div>
                {% endif %}

                {# Close multi-row first field container #}
                {% if is_single or forloop.last %}
                    </div>
                {% endif %}

                {% endfor %}

            </div>
        {% endwith %}
    {% endfor %}
</fieldset>
